package controller.product;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

import controller.invoice.InvoiceControl;
import lib.MyUtils;
import model.Laptop;
import model.Mobile;
import model.Supplier;
import model.Tablet;
import util.AutoCompleteDocument;
import view.product.ProductMainPanel;
import dao.LaptopDAO;
import dao.MobileDAO;
import dao.SupplierDAO;
import dao.TabletDAO;

public class MobileControl extends Observable implements ActionListener,
		MouseListener, Observer {
	private ProductMainPanel pro;
	private MobileDAO mobileDAO;
	private TabletDAO tabletDAO;
	private LaptopDAO laptopDAO;
	private SupplierDAO supDAO;
	public MobileControl(ProductMainPanel pro) {
		this.pro = pro;
		mobileDAO = new MobileDAO();
		tabletDAO = new TabletDAO();
		laptopDAO = new LaptopDAO();
		supDAO = new SupplierDAO();
		doFillcbbProdSupplier();
		autoComplete();
	}

	private boolean hasValues;

	private void remove() {
		pro.getCbbProdSupplier().removeAllItems();
	}

	private void doFillcbbProdSupplier() {
		List<Supplier> list = supDAO.showAllSupplier();
		if (hasValues) {
			remove();
		}
		for (Supplier i : list) {
			pro.getCbbProdSupplier().addItem(i.getName());
		}
		hasValues = true;
	}

	public void doSave(ActionEvent event) {
		String type = pro.getCbbProdProducttype().getSelectedItem().toString();
		String id = pro.getTxtProdId().getText();
		String name = pro.getTxtProdProductname().getText();
		String sup = pro.getCbbProdSupplier().getSelectedItem().toString();
		double purPrice = Double.parseDouble(pro.getTxtProdPurchaseprice()
				.getText());
		double salPrice = Double.parseDouble(pro.getTxtProdSaleprice()
				.getText());
		int quantity = Integer.parseInt(pro.getTxtProdQuantity().getText());
		String date = pro.getDateProdDate().getDate().toString();

		switch (type) {
		case "Mobile":
			Mobile mobile = new Mobile();
			String cpu = pro.getPnProdMobile().getTxtProdsubmobleCpu()
					.getText();

			double ram = Double.parseDouble(pro.getPnProdMobile()
					.getTxtProdsubmobleRam().getText());

			int sd = Integer.parseInt(pro.getPnProdMobile()
					.getTxtProdsubmobleSdcard().getText());

			double camera = Double.parseDouble(pro.getPnProdMobile()
					.getTxtProdsubmobleCamera().getText());

			String screen = pro.getPnProdMobile().getTxtProdsubmobleScreen()
					.getText();

			int battery = Integer.parseInt(pro.getPnProdMobile()
					.getTxtProdsubmobleBattery().getText());
			mobile.setId(id);
			mobile.setName(name);
			mobile.setSupplierName(sup);
			mobile.setPurPrice(purPrice);
			mobile.setSalPrice(salPrice);
			mobile.setQuantity(quantity);
			mobile.setDate(date);
			mobile.setScreen(screen);
			mobile.setCpu(cpu);
			mobile.setRam(ram);
			mobile.setCamera(camera);
			mobile.setBattery(battery);
			mobile.setSdCard(sd);
			if (mobileDAO.insertProduct(mobile)) {
				JOptionPane.showMessageDialog(null,
						"Insert Mobile successfully");
				doLoad();
				setChanged();
				notifyObservers();
			} else {
				JOptionPane.showMessageDialog(null, "Insert Mobile fail");
			}
			break;

		case "Tablet":
			Tablet tablet = new Tablet();
			String cpu1 = pro.getPnProdMobile().getTxtProdsubmobleCpu()
					.getText();

			double ram1 = Double.parseDouble(pro.getPnProdMobile()
					.getTxtProdsubmobleRam().getText());

			int sd1 = Integer.parseInt(pro.getPnProdMobile()
					.getTxtProdsubmobleSdcard().getText());

			double camera1 = Double.parseDouble(pro.getPnProdMobile()
					.getTxtProdsubmobleCamera().getText());

			String screen1 = pro.getPnProdMobile().getTxtProdsubmobleScreen()
					.getText();

			int battery1 = Integer.parseInt(pro.getPnProdMobile()
					.getTxtProdsubmobleBattery().getText());
			tablet.setId(id);
			tablet.setName(name);
			tablet.setSupplierName(sup);
			tablet.setPurPrice(purPrice);
			tablet.setSalPrice(salPrice);
			tablet.setQuantity(quantity);
			tablet.setDate(date);
			tablet.setScreen(screen1);
			tablet.setCpu(cpu1);
			tablet.setRam(ram1);
			tablet.setCamera(camera1);
			tablet.setBattery(battery1);
			tablet.setSdCard(sd1);
			if (tabletDAO.insertProduct(tablet)) {
				JOptionPane.showMessageDialog(null,
						"Insert Tablet successfully");
				doLoad();
				setChanged();
				notifyObservers();

			} else {
				JOptionPane.showMessageDialog(null, "Insert Tablet fail");
			}
			break;
		case "Laptop":

			Laptop laptop = new Laptop();
			laptop.setId(id);
			laptop.setName(name);
			laptop.setSupplierName(sup);
			laptop.setPurPrice(purPrice);
			laptop.setSalPrice(salPrice);
			laptop.setQuantity(quantity);
			laptop.setDate(date);

			String lCpu = pro.getPnProdLaptop().getTxtProdsublaptopCpu()
					.getText();
			int lHdd = Integer.parseInt(pro.getPnProdLaptop()
					.getTxtProdsublaptopHdd().getText());
			String lGraphic = pro.getPnProdLaptop()
					.getTxtProdsublaptopGraphic().getText();
			String lScreen = pro.getPnProdLaptop().getTxtProdsublaptopScreen()
					.getText();
			int lBattery = Integer.parseInt(pro.getPnProdLaptop()
					.getTxtProdsublaptopBattery().getText());
			String lDriver = pro.getPnProdLaptop().getTxtProdsublaptopDrive()
					.getText();
			int lmemory = Integer.parseInt(pro.getPnProdLaptop()
					.getTxtProdsublaptopMemory().getText());

			laptop.setCpu(lCpu);
			laptop.setHdd(lHdd);
			laptop.setGraphic(lGraphic);
			laptop.setScreen(lScreen);
			laptop.setBattery(lBattery);
			laptop.setDriver(lDriver);
			laptop.setMemory(lmemory);
			if (laptopDAO.insertLaptopt(laptop)) {
				JOptionPane.showMessageDialog(null,
						"Insert Laptop successfully");
				doLoad();
				setChanged();
				notifyObservers();
			} else {
				JOptionPane.showMessageDialog(null, "Insert Laptop fail");
			}
			break;
		}
	}

	public void doLoad() {
		String type = pro.getCbbProdProducttype().getSelectedItem().toString();
		switch (type) {
		case "Laptop":
			MyUtils.doLoadLaptop(pro);
			break;
		case "Tablet":
			MyUtils.doLoadTablet(pro);
			break;
		case "Mobile":
			MyUtils.doLoadMobile(pro);
			break;
		}
	}

	public void doDelete(ActionEvent event) {
		String type = pro.getCbbProdProducttype().getSelectedItem().toString();

		switch (type) {
		case "Mobile":
			int checkM = JOptionPane.showConfirmDialog(null,"Delete",
					"Do you want to delete?", JOptionPane.YES_NO_OPTION);
			if (checkM == JOptionPane.YES_OPTION) {
				String id = (String) pro.getTblProdListproduct().getValueAt(
						pro.getTblProdListproduct().getSelectedRow(), 0);
				mobileDAO.deleteMobile(mobileDAO.searchProduct(id));
				JOptionPane.showMessageDialog(null,
						"Delete Mobile successfully");
				doLoad();
				setChanged();
				notifyObservers();
			} else if (checkM == JOptionPane.CANCEL_OPTION) {
			}
			break;

		case "Tablet":
			int checkT = JOptionPane.showConfirmDialog(null,"Delete",
					"Do you want to delete?", JOptionPane.YES_NO_OPTION);
			if (checkT == JOptionPane.YES_OPTION) {
				String id = (String) pro.getTblProdListproduct().getValueAt(
						pro.getTblProdListproduct().getSelectedRow(), 0);
				tabletDAO.deleteTablet(tabletDAO.searchProduct(id));
				JOptionPane.showMessageDialog(null,
						"Delete Tablet successfully");
				doLoad();
				setChanged();
				notifyObservers();
			} else if (checkT == JOptionPane.CANCEL_OPTION) {
			}
			break;
		case "Laptop":
			int checkL = JOptionPane.showConfirmDialog(null,"Delete",
					"Do you want to delete?", JOptionPane.YES_NO_OPTION);
			if (checkL == JOptionPane.YES_OPTION) {
				String id = (String) pro.getTblProdListproduct().getValueAt(
						pro.getTblProdListproduct().getSelectedRow(), 0);
				laptopDAO.deleteLaptop(laptopDAO.searchLaptop(id));
				JOptionPane.showMessageDialog(null,
						"Delete Laptop successfully");
				doLoad();
				setChanged();
				notifyObservers();
			} else if (checkL == JOptionPane.CANCEL_OPTION) {
			}

			break;
		}

	}

	public void doSearch(ActionEvent event) {
		String type = pro.getCbbProdProducttype().getSelectedItem().toString();
		String m = pro.getCbbProdSearchby().getSelectedItem().toString();
		String id = pro.getTxtProdSearch().getText();
		DefaultTableModel dtm = new DefaultTableModel();
		MobileDAO mobileDAO = new MobileDAO();
		dtm.addColumn("Id");
		dtm.addColumn("Product name");
		dtm.addColumn("Supplier");
		dtm.addColumn("Purchase price");
		dtm.addColumn("Sale price");
		dtm.addColumn("Quantity");
		switch (type) {
		case "Mobile":
			switch (m) {
			case "name":
				for (Mobile i : mobileDAO.showAllMobileByAll(id)) {
					dtm.addRow(new Object[] { i.getId(), i.getName(),
							i.getSupplierName(), i.getPurPrice(),
							i.getSalPrice(), i.getQuantity() });
				}
				pro.getTblProdListproduct().setModel(dtm);
				break;

			case "infor":

				for (Mobile i : mobileDAO.showAllMobileByInfor(id)) {
					dtm.addRow(new Object[] { i.getId(), i.getName(),
							i.getSupplierName(), i.getPurPrice(),
							i.getSalPrice(), i.getQuantity() });
				}
				pro.getTblProdListproduct().setModel(dtm);
				break;
			}
			break;
		case "Tablet":
			switch (m) {
			case "name":

				for (Tablet i : tabletDAO.showAllMobileByAll(id)) {
					dtm.addRow(new Object[] { i.getId(), i.getName(),
							i.getSupplierName(), i.getPurPrice(),
							i.getSalPrice(), i.getQuantity() });
				}
				pro.getTblProdListproduct().setModel(dtm);
				break;

			case "infor":
				for (Tablet i : tabletDAO.showAllMobileByInfor(id)) {
					dtm.addRow(new Object[] { i.getId(), i.getName(),
							i.getSupplierName(), i.getPurPrice(),
							i.getSalPrice(), i.getQuantity() });
				}
				pro.getTblProdListproduct().setModel(dtm);
				break;
			}

			break;

		case "Laptop":
			switch (m) {
			case "name":
				for (Laptop i : laptopDAO.showAllLaptopByAll(id)) {
					dtm.addRow(new Object[] { i.getId(), i.getName(),
							i.getSupplierName(), i.getPurPrice(),
							i.getSalPrice(), i.getQuantity() });
				}
				pro.getTblProdListproduct().setModel(dtm);

				break;

			case "infor":
				for (Laptop i : laptopDAO.showAllMobileByInfor(id)) {
					dtm.addRow(new Object[] { i.getId(), i.getName(),
							i.getSupplierName(), i.getPurPrice(),
							i.getSalPrice(), i.getQuantity() });
				}
				pro.getTblProdListproduct().setModel(dtm);
				break;
			}
			break;
		}
	}

	public void doUpdate(ActionEvent event) {
		String key1 = (String) pro.getTblProdListproduct().getValueAt(
				pro.getTblProdListproduct().getSelectedRow(), 0);
		String type = pro.getCbbProdProducttype().getSelectedItem().toString();
		String name = pro.getTxtProdProductname().getText();
		String sup = pro.getCbbProdSupplier().getSelectedItem().toString();
		double purPrice = Double.parseDouble(pro.getTxtProdPurchaseprice()
				.getText());
		double salPrice = Double.parseDouble(pro.getTxtProdSaleprice()
				.getText());
		int quantity = Integer.parseInt(pro.getTxtProdQuantity().getText());
		String date = pro.getDateProdDate().getDate().toString();

		switch (type) {
		case "Mobile":
			Mobile mobile = mobileDAO.searchProduct(key1);
			String cpu = pro.getPnProdMobile().getTxtProdsubmobleCpu()
					.getText();

			double ram = Double.parseDouble(pro.getPnProdMobile()
					.getTxtProdsubmobleRam().getText());

			int sd = Integer.parseInt(pro.getPnProdMobile()
					.getTxtProdsubmobleSdcard().getText());

			double camera = Double.parseDouble(pro.getPnProdMobile()
					.getTxtProdsubmobleCamera().getText());

			String screen = pro.getPnProdMobile().getTxtProdsubmobleScreen()
					.getText();

			int battery = Integer.parseInt(pro.getPnProdMobile()
					.getTxtProdsubmobleBattery().getText());

			mobile.setName(name);
			mobile.setSupplierName(sup);
			mobile.setPurPrice(purPrice);
			mobile.setSalPrice(salPrice);
			mobile.setQuantity(quantity);
			mobile.setDate(date);
			mobile.setScreen(screen);
			mobile.setCpu(cpu);
			mobile.setRam(ram);
			mobile.setCamera(camera);
			mobile.setBattery(battery);
			mobile.setSdCard(sd);
			if (mobileDAO.updateProduct(mobileDAO.searchProduct(key1))) {
				JOptionPane.showMessageDialog(null,
						"Update Mobile successfully");
				doLoad();
				setChanged();
				notifyObservers();
			} else {
				JOptionPane.showMessageDialog(null, "Update Mobile fail");
			}
			break;

		case "Tablet":
			Tablet tablet = tabletDAO.searchProduct(key1);
			String cpu1 = pro.getPnProdMobile().getTxtProdsubmobleCpu()
					.getText();

			double ram1 = Double.parseDouble(pro.getPnProdMobile()
					.getTxtProdsubmobleRam().getText());

			int sd1 = Integer.parseInt(pro.getPnProdMobile()
					.getTxtProdsubmobleSdcard().getText());

			double camera1 = Double.parseDouble(pro.getPnProdMobile()
					.getTxtProdsubmobleCamera().getText());

			String screen1 = pro.getPnProdMobile().getTxtProdsubmobleScreen()
					.getText();

			int battery1 = Integer.parseInt(pro.getPnProdMobile()
					.getTxtProdsubmobleBattery().getText());
			tablet.setName(name);
			tablet.setSupplierName(sup);
			tablet.setPurPrice(purPrice);
			tablet.setSalPrice(salPrice);
			tablet.setQuantity(quantity);
			tablet.setDate(date);
			tablet.setScreen(screen1);
			tablet.setCpu(cpu1);
			tablet.setRam(ram1);
			tablet.setCamera(camera1);
			tablet.setBattery(battery1);
			tablet.setSdCard(sd1);
			if (tabletDAO.updateProduct(tabletDAO.searchProduct(key1))) {
				JOptionPane.showMessageDialog(null,
						"Update Laptop successfully");
				doLoad();
				setChanged();
				notifyObservers();
			} else {
				JOptionPane.showMessageDialog(null, "Update Laptop fail");
			}
			break;
		
		case "Laptop":

			Laptop laptop = laptopDAO.searchLaptop(key1);
			laptop.setName(name);
			laptop.setSupplierName(sup);
			laptop.setPurPrice(purPrice);
			laptop.setSalPrice(salPrice);
			laptop.setQuantity(quantity);
			laptop.setDate(date);

			String lCpu = pro.getPnProdLaptop().getTxtProdsublaptopCpu()
					.getText();
			int lHdd = Integer.parseInt(pro.getPnProdLaptop()
					.getTxtProdsublaptopHdd().getText());
			String lGraphic = pro.getPnProdLaptop()
					.getTxtProdsublaptopGraphic().getText();
			String lScreen = pro.getPnProdLaptop().getTxtProdsublaptopScreen()
					.getText();
			int lBattery = Integer.parseInt(pro.getPnProdLaptop()
					.getTxtProdsublaptopBattery().getText());
			String lDriver = pro.getPnProdLaptop().getTxtProdsublaptopDrive()
					.getText();
			int lmemory = Integer.parseInt(pro.getPnProdLaptop()
					.getTxtProdsublaptopMemory().getText());

			laptop.setCpu(lCpu);
			laptop.setHdd(lHdd);
			laptop.setGraphic(lGraphic);
			laptop.setScreen(lScreen);
			laptop.setBattery(lBattery);
			laptop.setDriver(lDriver);
			laptop.setMemory(lmemory);
			if (laptopDAO.updateProduct(laptopDAO.searchLaptop(key1))) {
				JOptionPane.showMessageDialog(null,
						"Update Laptop successfully");
				doLoad();
				setChanged();
				notifyObservers();
			} else {
				JOptionPane.showMessageDialog(null, "Update Laptop fail");
			}
			break;
		}
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		String type = pro.getCbbProdProducttype().getSelectedItem().toString();
		switch (type) {
		case "Mobile":
			String idM = (String) pro.getTblProdListproduct().getValueAt(
					pro.getTblProdListproduct().getSelectedRow(), 0);

			Mobile mobile = (Mobile) mobileDAO.searchProduct(idM);
			pro.getTxtProdId().setText(mobile.getId());
			pro.getTxtProdProductname().setText(mobile.getName());
			pro.getCbbProdSupplier().setSelectedItem(mobile.getSupplierName());
			pro.getTxtProdPurchaseprice().setText(mobile.getPurPrice() + "");
			pro.getTxtProdSaleprice().setText(mobile.getSalPrice() + "");
			pro.getTxtProdQuantity().setText(mobile.getQuantity() + "");

			pro.getPnProdMobile().getTxtProdsubmobleCpu()
					.setText(mobile.getCpu());
			pro.getPnProdMobile().getTxtProdsubmobleRam()
					.setText(mobile.getRam() + "");
			pro.getPnProdMobile().getTxtProdsubmobleScreen()
					.setText(mobile.getScreen());
			pro.getPnProdMobile().getTxtProdsubmobleSdcard()
					.setText(mobile.getSdCard() + "");
			pro.getPnProdMobile().getTxtProdsubmobleBattery()
					.setText(mobile.getBattery() + "");
			pro.getPnProdMobile().getTxtProdsubmobleCamera()
					.setText(mobile.getCamera() + "");

			break;
		case "Tablet":
			String idT = (String) pro.getTblProdListproduct().getValueAt(
					pro.getTblProdListproduct().getSelectedRow(), 0);

			Tablet tablet = (Tablet) tabletDAO.searchProduct(idT);
			pro.getTxtProdId().setText(tablet.getId());
			pro.getTxtProdProductname().setText(tablet.getName());
			pro.getCbbProdSupplier().setSelectedItem(tablet.getSupplierName());
			pro.getTxtProdPurchaseprice().setText(tablet.getPurPrice() + "");
			pro.getTxtProdSaleprice().setText(tablet.getSalPrice() + "");
			pro.getTxtProdQuantity().setText(tablet.getQuantity() + "");

			pro.getPnProdMobile().getTxtProdsubmobleCpu()
					.setText(tablet.getCpu());
			pro.getPnProdMobile().getTxtProdsubmobleRam()
					.setText(tablet.getRam() + "");
			pro.getPnProdMobile().getTxtProdsubmobleScreen()
					.setText(tablet.getScreen());
			pro.getPnProdMobile().getTxtProdsubmobleSdcard()
					.setText(tablet.getSdCard() + "");
			pro.getPnProdMobile().getTxtProdsubmobleBattery()
					.setText(tablet.getBattery() + "");
			pro.getPnProdMobile().getTxtProdsubmobleCamera()
					.setText(tablet.getCamera() + "");
			break;
		case "Laptop":
			String idL = (String) pro.getTblProdListproduct().getValueAt(
					pro.getTblProdListproduct().getSelectedRow(), 0);

			Laptop laptop = (Laptop) laptopDAO.searchLaptop(idL);
			pro.getTxtProdId().setText(laptop.getId());
			pro.getTxtProdProductname().setText(laptop.getName());
			pro.getCbbProdSupplier().setSelectedItem(laptop.getSupplierName());
			pro.getTxtProdPurchaseprice().setText(laptop.getPurPrice() + "");
			pro.getTxtProdSaleprice().setText(laptop.getSalPrice() + "");
			pro.getTxtProdQuantity().setText(laptop.getQuantity() + "");

			pro.getPnProdLaptop().getTxtProdsublaptopBattery()
					.setText(laptop.getBattery() + "");
			pro.getPnProdLaptop().getTxtProdsublaptopCpu()
					.setText(laptop.getCpu());
			pro.getPnProdLaptop().getTxtProdsublaptopDrive()
					.setText(laptop.getDriver());
			pro.getPnProdLaptop().getTxtProdsublaptopGraphic()
					.setText(laptop.getGraphic());
			pro.getPnProdLaptop().getTxtProdsublaptopHdd()
					.setText(laptop.getHdd() + "");
			pro.getPnProdLaptop().getTxtProdsublaptopMemory()
					.setText(laptop.getMemory() + "");
			pro.getPnProdLaptop().getTxtProdsublaptopScreen()
					.setText(laptop.getScreen());
			break;
		}

	}

	@Override
	public void mouseEntered(MouseEvent e) {

	}

	@Override
	public void mouseExited(MouseEvent e) {

	}

	@Override
	public void mousePressed(MouseEvent e) {

	}

	@Override
	public void mouseReleased(MouseEvent e) {

	}

	@Override
	public void actionPerformed(ActionEvent event) {
		if (event.getSource() == pro.getBtnProdAdd()) {
			doSave(event);
		} else if (event.getSource() == pro.getCbbProdProducttype()) {
			doLoad();
		} else if (event.getSource() == pro.getBtnProdDelete()) {
			doDelete(event);
		} else if (event.getSource() == pro.getBtnProdSearch()) {
			doSearch(event);
		} else if (event.getSource() == pro.getBtnProdUpdate()) {
			doUpdate(event);
		} else if (event.getSource() == pro.getBtnProdCancel()) {
			doReset(event);
		}
	}

	private void doReset(ActionEvent event) {
		String type = pro.getCbbProdProducttype().getSelectedItem().toString();
		switch (type) {
		case "Mobile":
		case "Tablet":
			pro.getTxtProdId().setText("");
			pro.getTxtProdProductname().setText("");
			pro.getTxtProdPurchaseprice().setText("");
			pro.getTxtProdQuantity().setText("");
			pro.getTxtProdSaleprice().setText("");
			pro.getTxtProdSearch().setText("");
			pro.getPnProdMobile().getTxtProdsubmobleBattery().setText("");
			pro.getPnProdMobile().getTxtProdsubmobleCamera().setText("");
			pro.getPnProdMobile().getTxtProdsubmobleCpu().setText("");
			pro.getPnProdMobile().getTxtProdsubmobleRam().setText("");
			pro.getPnProdMobile().getTxtProdsubmobleScreen().setText("");
			pro.getPnProdMobile().getTxtProdsubmobleSdcard().setText("");
			break;
		case "Laptop":
			pro.getTxtProdId().setText("");
			pro.getTxtProdProductname().setText("");
			pro.getTxtProdPurchaseprice().setText("");
			pro.getTxtProdQuantity().setText("");
			pro.getTxtProdSaleprice().setText("");
			pro.getTxtProdSearch().setText("");
			pro.getPnProdLaptop().getTxtProdsublaptopBattery().setText("");
			pro.getPnProdLaptop().getTxtProdsublaptopCpu().setText("");
			pro.getPnProdLaptop().getTxtProdsublaptopDrive().setText("");
			pro.getPnProdLaptop().getTxtProdsublaptopHdd().setText("");
			pro.getPnProdLaptop().getTxtProdsublaptopGraphic().setText("");
			pro.getPnProdLaptop().getTxtProdsublaptopMemory().setText("");
			pro.getPnProdLaptop().getTxtProdsublaptopScreen().setText("");
			break;
		}
	}

	@Override
	public void update(Observable obs, Object value) {
		if(obs instanceof SupplierControl)
			doFillcbbProdSupplier();
		else if(obs instanceof InvoiceControl)
			doLoad();
		
	}

	private void autoComplete() {
		pro.getCbbProdSupplier().setEditable(true);
		new AutoCompleteDocument(pro.getCbbProdSupplier());
	}
}